home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 April: Mac OS SDK / Dev.CD Apr 98 SDK2.toast / Development Kits (Disc 2) / ScriptX / Documentation / Code Examples from Docs / compguid / printing / docprn / jailbird.sx < prev    next >
Encoding:
Text File  |  1996-05-21  |  7.4 KB  |  261 lines  |  [TEXT/ttxt]

  1. -- Filename:
  2. --     JAILBIRD.SX
  3.  
  4. -- Other Files Required: 
  5. --     NONE
  6.  
  7. -- Purpose:
  8. --     Demonstrates a simple working document
  9.  
  10. -- Specialized Classes:
  11. --     None
  12.  
  13. -- Instructions to User:
  14. --     This is the main script for the creation of the document object.  To
  15. -- create the title container, run the loadme.sx script.  The loadme script
  16. -- will then call the media.sx and jailbird.sx scripts.
  17. --
  18. --        When the jailbird.sxt title runs a window will appear with the title page.
  19. -- Click any where in this page to go to the next page.  Subsequent pages will
  20. -- contain forward and backward buttons for traversing the document.
  21.  
  22. -- Author:
  23. --     Kim Swix
  24.  
  25. ------------------------------------------------------------------------
  26.  
  27. in module docModule
  28.  
  29. -- ***********************************************************************
  30. -- Functions
  31. -- ***********************************************************************
  32.  
  33. function findPresenter presenter parentClass ->
  34. (   repeat while (presenter !== undefined) do
  35.     (   if (isAKindOf presenter parentClass) do
  36.            (return presenter)
  37.         presenter := presenter.presentedBy
  38.     )
  39.     undefined
  40. )
  41.  
  42. function butFwd ad self ->
  43.   local doc, bm
  44.   doc := findPresenter self Document
  45.   bm := doc[doc.cursor].frame[10].presenter.target
  46.   forward doc
  47.   makepurgeable bm
  48.   if doc.cursor = doc.size do
  49.      self.enabled := false
  50. )
  51.  
  52. function butBack ad self ->
  53.   local doc, bm
  54.   doc := findPresenter self Document
  55.   bm := doc[doc.cursor].frame[10].presenter.target
  56.   backward doc
  57.   makepurgeable bm
  58.   if doc.cursor < doc.size do
  59.      ad.enabled := true
  60. )
  61.  
  62. function makeTitleLayer bbox ->
  63. (
  64.     local tlayer, sh, bkgndElem
  65.     tlayer := new pageLayer boundary:bbox
  66.     sh := new twodshape boundary:docCont["1000.bmp" as String]
  67.     bkgndElem := new pageElement boundary:sh.boundary presenter:sh target:docCont["1000.bmp" as String]
  68.     bkgndElem.x := bkgndElem.y := 0
  69.     append tlayer bkgndElem
  70.     
  71.     local but, ctl, butElem
  72.     but := new pushbutton
  73.     but.releasedPresenter := (new twodshape boundary:bbox fill:undefined stroke:undefined)
  74.     but.pressedPresenter := (new twodshape boundary:bbox fill:undefined stroke:undefined)
  75.     but.activateAction := ( ad item -> forward doc)
  76.     butElem := new pageElement boundary:but.boundary presenter:but target:but.target
  77.     prepend tlayer butElem
  78.     
  79.     ctl := new actuatorController space:tlayer
  80.     deleteOne ctl.protocols Actuator
  81.     append ctl.protocols PageElement
  82.     ctl.wholespace := true
  83.     
  84.     return tlayer
  85. )
  86.  
  87. function makeTextBox txt brush ->
  88. (
  89.     local tb, fnt
  90.     tb := new textPresenter boundary:(new rect x2:100 y2:25) target:txt
  91.     fnt := new platformFont name:"Helvetica" windowsName:"Arial"
  92.     setdefaultattr tb  @font  fnt
  93.     setdefaultattr tb @size 12
  94.     setdefaultattr tb @brush brush
  95.     return tb
  96. )
  97.  
  98. function makeMugLayer bbox ->
  99. (
  100.     local mlayer, tb, pe, bp
  101.     
  102.     mlayer := new pageLayer boundary:bbox
  103.     bp := new brush color:bluecolor
  104.     
  105.     -- Create the Name page element    
  106.     tb := makeTextBox ("Name:  " as text) blackbrush
  107.     pe := new pageElement boundary:tb.boundary presenter:tb target:("Name:  " as text)
  108.     pe.x := 20
  109.     pe.y := 125
  110.     append mlayer pe
  111.     
  112.     -- Create the DOB page element
  113.     tb := makeTextBox ("DOB:  " as text) blackbrush
  114.     pe := new pageElement boundary:tb.boundary presenter:tb target:("DOB:  " as text)
  115.     pe.x := 20
  116.     pe.y := 148
  117.     append mlayer pe
  118.     
  119.     -- Create the Height element
  120.     tb := makeTextBox ("Height:  " as text) blackbrush
  121.     pe := new pageElement boundary:tb.boundary presenter:tb target:("Height:  " as text)
  122.     pe.x := 20
  123.     pe.y := 171
  124.     append mlayer pe
  125.  
  126.     -- Create the Weight element
  127.     tb := makeTextBox ("Weight:  " as text) blackbrush
  128.     pe := new pageElement boundary:tb.boundary presenter:tb target:("Weight:  " as text)
  129.     pe.x := 20
  130.     pe.y := 194
  131.     append mlayer pe
  132.     
  133.     -- Create the PageNo element
  134.     tb := makeTextBox (" " as text) blackbrush
  135.     pe := new pageElement boundary:tb.boundary presenter:tb \
  136.       target:( e -> getNth (getparentData e Page) 1)
  137.     pe.x := 20
  138.     pe.y := 225
  139.     append mlayer pe
  140.     
  141.     -- Create the Name Field element
  142.     tb := makeTextBox (" " as text) bp
  143.     pe := new pageElement boundary:tb.boundary presenter:tb \
  144.       target:( e -> getNth (getparentData e Page) 2)
  145.     pe.x := 100
  146.     pe.y := 125
  147.     append mlayer pe
  148.     
  149.     -- Create the DOB Field element
  150.     tb := makeTextBox (" " as text) bp
  151.     pe := new pageElement boundary:tb.boundary presenter:tb \
  152.       target:( e -> getNth (getparentData e Page) 3)
  153.     pe.x := 100
  154.     pe.y := 148
  155.     append mlayer pe
  156.  
  157.     -- Create the Height Field element
  158.     tb := makeTextBox (" " as text) bp
  159.     pe := new pageElement boundary:tb.boundary presenter:tb \
  160.       target:( e -> getNth (getparentData e Page) 4)
  161.     pe.x := 100
  162.     pe.y := 171
  163.     append mlayer pe
  164.     
  165.     -- Create the Weight Field element
  166.     tb := makeTextBox (" " as text) bp
  167.     pe := new pageElement boundary:tb.boundary presenter:tb \
  168.       target:( e -> getNth (getparentData e Page) 5)
  169.     pe.x := 100
  170.     pe.y := 194
  171.     append mlayer pe
  172.  
  173.     -- Create the mugshot element
  174.     local mugShape := new twodshape boundary:docCont["1001.bmp" as String]
  175.     pe := new pageElement boundary:mugShape.boundary presenter:mugShape \
  176.       target:  (e -> getNth (getParentData e Page) 6)
  177.     pe.x := pe.y := 20
  178.     append mlayer pe
  179.     
  180.     -- Create the navigational buttons
  181.     local tri1, tri2, gp, rp, rpDull, blDull
  182.     gp := new brush color:greencolor
  183.     rp := new brush color:redcolor
  184.     rpDull := new brush color:redcolor pattern:grayPattern
  185.     blDull := new brush color:blackcolor pattern:grayPattern
  186.     
  187.     tri1 := new path
  188.     moveto tri1 0 0
  189.     lineto tri1 0 50
  190.     lineto tri1 25 25
  191.     closePath tri1
  192.     
  193.     local fwd := new pushButton
  194.     fwd.pressedPresenter := (new twodshape boundary:tri1 stroke:blackbrush fill:gp)
  195.     fwd.releasedPresenter := (new twodshape boundary:tri1 stroke:blackbrush fill:rp)
  196.     fwd.disabledPresenter := (new twodshape boundary:tri1 stroke:blDull fill:rpDull)
  197.     fwd.activateAction := butFwd
  198.     
  199.     tri2 := new path
  200.     moveto tri2 25 0
  201.     lineto tri2 25 50
  202.     lineto tri2 0 25
  203.     closepath tri2
  204.     
  205.     local bwd := new pushbutton
  206.     bwd.pressedPresenter := (new twodshape boundary:tri2 stroke:blackbrush fill:gp)
  207.     bwd.releasedPresenter := (new twodshape boundary:tri2 stroke:blackbrush fill:rp)
  208.     bwd.disabledPresenter := (new twodshape boundary:tri2 stroke:blDull fill:rpDull)
  209.     bwd.activateAction := butBack
  210.     bwd.authorData := fwd
  211.     
  212.     pe := new pageElement boundary:fwd.boundary presenter:fwd target:fwd.target
  213.     pe.x := 265
  214.     pe.y := 250
  215.     append mlayer pe
  216.     
  217.     pe := new pageElement boundary:bwd.boundary presenter:bwd target:bwd.target
  218.     pe.x := 10
  219.     pe.y := 250
  220.     append mlayer pe
  221.     
  222.     local ctl
  223.     ctl := new actuatorController space:mlayer
  224.     deleteOne ctl.protocols Actuator
  225.     append ctl.protocols PageElement
  226.     ctl.wholespace := true
  227.     
  228.     return mlayer
  229. )
  230.  
  231. function makePage bbox frame data ->
  232. (
  233.     local pg
  234.     pg := new page boundary:bbox frame:frame target:data
  235.     
  236.     return pg
  237. )
  238.  
  239. function makeDocument ->
  240. (
  241.     local doc, titleLayer, mugShotLayer, prect
  242.     prect := new rect x2:300 y2:300
  243.     doc := new MyDocumentClass boundary:prect
  244.     doc.name := "JailBirds"
  245.     
  246.     titleLayer := makeTitleLayer prect
  247.     mugShotLayer := makeMugLayer prect
  248.     
  249.     append doc (makePage prect titleLayer undefined)
  250.     append doc (makePage prect mugShotLayer #(("Page 2" as text), ("Barry"as text),\
  251.       ( "2-12-93" as text), ("5 ft." as text), ("125 lbs." as text), docCont["1001.bmp" as String]))
  252.     append doc (makePage prect mugShotLayer #(("Page 3" as text), ("Willie" as text),\
  253.       ( "1-29-93" as text), ("6 in." as text), ("3 oz." as text), docCont["1002.bmp" as String]))
  254.     append doc (makePage prect mugShotLayer #(("Page 4" as text), ("Cotton" as text),\
  255.       ( "11-19-62" as text), ("1 ft." as text), ("3 lbs." as text), docCont["1003.bmp" as String]))
  256.       
  257.     return doc
  258. )
  259.